/**
 * 
 */
package com.gametheoryserver.gui.sum.state;

import com.gametheoryserver.gui.sum.PlaySumGame;
import com.gametheoryserver.logic.Game;
import com.vaadin.ui.HorizontalLayout;

/**
 * @author Tomas Barak
 * 
 */
public class RemoveGameState extends PlaySumGameStateHolder implements ISumGameState {

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.gametheoryserver.gui.sum.state.ISumGameState#refreshGame(com. gametheoryserver.gui.sum.PlaySumGame)
	 */
	@Override
	public void refreshGame(PlaySumGame playSum) {
		Integer data = (Integer) playSum.getData();
		HorizontalLayout layout = new HorizontalLayout();
		Game game = new Game();
		for (HorizontalLayout h : playSum.getInfoLayoutList()) {
			if (h.getData().equals(data))
				layout = h;
		}
		for (Game g : playSum.getGamesList()) {
			if (g.getData().equals(data))
				game = g;
		}
		playSum.getInfoLayoutList().remove(layout);
		playSum.getGamesList().remove(game);
		playSum.repaintInfo();
		playSum.setGameNumber(playSum.getGameNumber() - 1);
		if (playSum.getGameNumber() == 1) {
			playSum.getStartBtn().setEnabled(false);
		}
	}

}
